import React from 'react'
import { Form, Row, Col, Button, Space } from 'antd'
import type { FormProps } from 'antd'

interface SearchFormProps extends FormProps {
  onSearch?: (values: any) => void
  onReset?: () => void
  children: React.ReactNode
}

const SearchForm: React.FC<SearchFormProps> = ({
  onSearch,
  onReset,
  children,
  ...props
}) => {
  const [form] = Form.useForm()

  const handleReset = () => {
    form.resetFields()
    onReset?.()
  }

  const handleSearch = async () => {
    const values = await form.validateFields()
    onSearch?.(values)
  }

  return (
    <Form
      form={form}
      layout="horizontal"
      {...props}
    >
      <Row gutter={16}>
        {children}
        <Col>
          <Space>
            <Button type="primary" onClick={handleSearch}>
              搜索
            </Button>
            <Button onClick={handleReset}>
              重置
            </Button>
          </Space>
        </Col>
      </Row>
    </Form>
  )
}

export default SearchForm 